package io.renren.modules.student.service.impl;

import io.renren.modules.school.entity.ProfessionEntity;
import io.renren.modules.school.entity.SchoolPredictor;
import io.renren.modules.school.entity.UniversityEntity;
import io.renren.modules.student.dao.StudentDao;
import io.renren.modules.student.entity.StudentProfession;
import io.renren.modules.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentDao studentDao;

    @Override
    public void saveStudentUniversity(UniversityEntity universityEntity) {
        studentDao.saveStudentUniversity(universityEntity);
        UniversityEntity universityEntity1= studentDao.getNewsStudentUniversity();
        List<StudentProfession> professionEntities=universityEntity.getProfessions();
        int i=1;
        for(StudentProfession professionEntity:professionEntities){
            if(!"".equals(professionEntity.getName())){
                professionEntity.setSchoolId(universityEntity1.getId());
                professionEntity.setSort(i);
                professionEntity.setUserBackId(universityEntity.getUserBackId());
                i++;
                studentDao.saveStudentProfession(professionEntity);
                System.out.println("");
            }
        }

        System.out.println("");
    }

    @Override
    public List<UniversityEntity> getUniversityListByStudentId(Integer id) {
        List<UniversityEntity> list=studentDao.getUniversityListByStudentId(id);
        List<UniversityEntity> returnList=new ArrayList<>();
        int num=12;
        if(list!=null){
            num=12-list.size();
        }
        for(UniversityEntity u:list){
            u.setProfessions(studentDao.getProfessionByUserBackId(u.getId(),id));
            returnList.add(u);
        }
        for(int i=0;i<num;i++){
            UniversityEntity u=new UniversityEntity();
            u.setName("");
            u.setCode("");
            u.setProfessions(new ArrayList<StudentProfession>());
            returnList.add(u);
        }
        return returnList;
    }

    @Override
    public List<ProfessionEntity> getProfessionListByUniversityIds(List<SchoolPredictor> list) {
        return studentDao.getProfessionListByUniversityIds(list);
    }


}
